package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.PayWayModel;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class PayWayAdapter extends ItemAdapter<PayWayModel.DataBean, PayWayAdapter.InviteRecordViewHolder> {


    private Context context;
    private String title = "支付宝";
    private boolean isFirst = true;

    public PayWayAdapter(Context context) {
        super(context);
        this.context = context;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public InviteRecordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new InviteRecordViewHolder(inflate(R.layout.item_pay_way, parent));
    }

    @Override
    public void onBindViewHolder(InviteRecordViewHolder holder, int position) {
        PayWayModel.DataBean item = getItem(position);
        holder.item = item;
        Glide.with(context).load(item.payment_logo).error(R.mipmap.bank_default).into(holder.imgPayType);
        holder.txtPayType.setText(item.payment_name);
        holder.txtPayContent.setText(item.payment_description);
        if (item.isCheck) {
            holder.cbPay.setImageResource(R.mipmap.img_pay_cb_open);
            holder.cbPay.setVisibility(View.VISIBLE);
        } else {
            holder.cbPay.setVisibility(View.INVISIBLE);
        }
    }

    public interface OnCheckListener {
        void onClick(String way, String pay_id, String payment_description, String title);
    }

    private OnCheckListener onCheckListener;

    public void setShareClickListener(OnCheckListener onCheckListener) {
        this.onCheckListener = onCheckListener;
    }

    class InviteRecordViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @BindView(R.id.img_pay_type)
        ImageView imgPayType;
        @BindView(R.id.txt_pay_type)
        TextView txtPayType;
        @BindView(R.id.txt_pay_content)
        TextView txtPayContent;
        @BindView(R.id.cb_pay)
        ImageView cbPay;
        @BindView(R.id.layout_one)
        RelativeLayout layoutOne;
        PayWayModel.DataBean item;

        private InviteRecordViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
            cbPay.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (onCheckListener != null) {
                onCheckListener.onClick(item.payment_class_name, item.payment_id + "", item.payment_description, item.payment_name);
            }
        }
    }
}
